package com.ruoyi.system.service.impl;

import java.util.HashMap;
import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.domain.ShMarketTj;
import com.ruoyi.system.service.IShProductService;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ShMarketMapper;
import com.ruoyi.system.domain.ShMarket;
import com.ruoyi.system.service.IShMarketService;

/**
 * 商品分销信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-07-18
 */
@Service
public class ShMarketServiceImpl implements IShMarketService 
{
    @Autowired
    private ShMarketMapper shMarketMapper;

    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private IShProductService shProductService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询商品分销信息
     * 
     * @param id 商品分销信息主键
     * @return 商品分销信息
     */
    @Override
    public ShMarket selectShMarketById(Long id)
    {
        return shMarketMapper.selectShMarketById(id);
    }

    /**
     * 查询商品分销信息列表
     * 
     * @param shMarket 商品分销信息
     * @return 商品分销信息
     */
    @Override
    public List<ShMarket> selectShMarketList(ShMarket shMarket)
    {
        List<ShMarket> list = shMarketMapper.selectShMarketList(shMarket);
        HashMap<Long, String> shopMap = sysDeptService.getShopMap();
        HashMap<Long, String> productNameMap = shProductService.getProductMap();
        HashMap<Long, SysUser> userNameMap = sysUserService.getUserMap();
        for (ShMarket obj:list) {
            obj.setShopName(shopMap.get(obj.getShopId()));
            obj.setProductName(productNameMap.get(obj.getProductId()));
            if (null!=userNameMap) {
                SysUser userParam = userNameMap.get(obj.getCreateBy());
                obj.setCreateByName(userParam.getUserName());
                obj.setPhone(userParam.getPhonenumber());
            }
        }
        return list;
    }

    @Override
    public List<ShMarketTj> selectMarketAmountTjPayList(ShMarket shMarket)
    {
        return shMarketMapper.selectMarketAmountTjPayList(shMarket);
    }

    @Override
    public List<ShMarketTj> selectMarketTjPayList(ShMarket shMarket)
    {
        return shMarketMapper.selectMarketTjPayList(shMarket);
    }

    /**
     * 新增商品分销信息
     * 
     * @param shMarket 商品分销信息
     * @return 结果
     */
    @Override
    public int insertShMarket(ShMarket shMarket)
    {
        shMarket.setCreateTime(DateUtils.getNowDate());
        return shMarketMapper.insertShMarket(shMarket);
    }

    /**
     * 修改商品分销信息
     * 
     * @param shMarket 商品分销信息
     * @return 结果
     */
    @Override
    public int updateShMarket(ShMarket shMarket)
    {
        return shMarketMapper.updateShMarket(shMarket);
    }

    /**
     * 批量删除商品分销信息
     * 
     * @param ids 需要删除的商品分销信息主键
     * @return 结果
     */
    @Override
    public int deleteShMarketByIds(Long[] ids)
    {
        return shMarketMapper.deleteShMarketByIds(ids);
    }

    /**
     * 删除商品分销信息信息
     * 
     * @param id 商品分销信息主键
     * @return 结果
     */
    @Override
    public int deleteShMarketById(Long id)
    {
        return shMarketMapper.deleteShMarketById(id);
    }
}
